package com.goodving.guli.utility;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.support.v4.app.NotificationCompat;
import android.widget.RemoteViews;

import com.androidquery.util.AQUtility;
import com.goodving.guli.R;
import com.goodving.guli.activity.SplashScreenActivity;
import com.goodving.guli.model.DailyStats;

import java.text.NumberFormat;

/**
 * Created by Administrator on 2015-11-17.
 */
public class C1297s {
    public static void m11552a(Context context) {
        if (C1481u.m12082d().getBoolean(C1465g.cE, true)) {
            NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            Intent intent = new Intent("android.intent.action.MAIN");
            intent.addCategory("android.intent.category.LAUNCHER");
            intent.setClass(context, SplashScreenActivity.class);
            intent.setFlags(270532608);

            Notification c = new NotificationCompat.Builder(context).setWhen(System.currentTimeMillis()).setSmallIcon((int) R.drawable.ic_notification_small).setContentIntent(PendingIntent.getActivity(context, C1465g.bS, intent, PendingIntent.FLAG_UPDATE_CURRENT)).build();
            c.flags = 2;
            c.contentView = new RemoteViews(context.getPackageName(), R.layout.app_notification_widget);
            C1297s.m11551a(context, c.contentView);
            notificationManager.notify(C1465g.cs, c);

            return;
        }
        ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).cancel(C1465g.cs);
    }

    public static RemoteViews m11551a(Context context, RemoteViews remoteViews) {
        int t;
        double d = Constants.DEFAULT_INTENSITY;
        DailyStats a = null;
        if (a != null) {
            if (a.getGoalStep() <= 0) {
                a.setGoalStep(C1481u.m12097s());
            }
            t = a.getGoalStep();
        } else {
            t = 0;
        }
        double f = ((double) a.getStepCnt()) / ((double) t);
        if (f < Constants.DEFAULT_INTENSITY) {
            d = f;
        }
        NumberFormat percentInstance = NumberFormat.getPercentInstance();
        percentInstance.setMinimumFractionDigits(0);
        remoteViews.setTextViewText(R.id.tv_widget_steps, "" + a.getStepCnt());
        remoteViews.setTextViewText(R.id.tv_widget_cals, "" + String.format("%.0f", new Object[]{Double.valueOf(a.getTotalCal())}));
        remoteViews.setTextViewText(R.id.tv_widget_goal_percent, "" + percentInstance.format(d));
        Bitmap createBitmap = Bitmap.createBitmap(AQUtility.dip2pixel(context, 47.0f), AQUtility.dip2pixel(context, 47.0f), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(createBitmap);
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColor(Color.rgb(C0640l.f1907a, C0640l.f1907a, C0640l.f1907a));
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth((float) AQUtility.dip2pixel(context, 3.0f));
        canvas.drawArc(new RectF((float) AQUtility.dip2pixel(context, 2.0f), (float) AQUtility.dip2pixel(context, 2.0f), (float) AQUtility.dip2pixel(context, 45.0f), (float) AQUtility.dip2pixel(context, 45.0f)), (float) -90, (float) ((int) (d * 360.0d)), false, paint);
        remoteViews.setImageViewBitmap(R.id.percent_arc_iv, createBitmap);
        return remoteViews;
    }
}

